package com.itheima.tliasmanagement.controller;

import com.itheima.tliasmanagement.dto.AddStudentDto;
import com.itheima.tliasmanagement.dto.StudentListDto;
import com.itheima.tliasmanagement.dto.UpdateStudentDto;
import com.itheima.tliasmanagement.service.StudentService;
import com.itheima.tliasmanagement.vo.PageBean;
import com.itheima.tliasmanagement.vo.Result2;
import com.itheima.tliasmanagement.vo.StudentListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result2<PageBean<StudentListVo>> pageQuery(StudentListDto dto){
        PageBean<StudentListVo> page = studentService.pageQuery(dto);
        return Result2.ok(page);
    }

    @PostMapping
    public Result2 addStudent(@RequestBody AddStudentDto dto){
        studentService.addStudent(dto);
        return Result2.ok();
    }

    @GetMapping("{id}")
    public Result2<StudentListVo> getById(@PathVariable("id")Integer id){
        StudentListVo student = studentService.getById(id);
        return Result2.ok(student);
    }

    @PutMapping
    public Result2 updateStudent(@RequestBody UpdateStudentDto dto){
        studentService.updateStudent(dto);
        return Result2.ok();
    }

    @DeleteMapping("{ids}")
    public Result2 deleteByIds(@PathVariable("ids")List<Integer> ids){
        studentService.deleteByIds(ids);
        return Result2.ok();
    }

    @PutMapping("violation/{id}/{score}")
    public Result2 violation(@PathVariable("id")Integer id, @PathVariable("score") Integer score){
        studentService.violation(id, score);
        return Result2.ok();
    }


}
